package top.lt.lt_ssm.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.lt.lt_ssm.bean.evaluate;
import top.lt.lt_ssm.bean.orders;
import top.lt.lt_ssm.service.ordersService;
import top.lt.lt_ssm.util.SimpleResult;

@Controller
@RequestMapping("/order")
public class OrderController {
	@Resource
	private ordersService ordersService;
	
	
	@RequestMapping("/GetAll")
	public @ResponseBody SimpleResult GetAll() {
		List<orders> allOrders = ordersService.getAllOrders();
		allOrders.forEach(s->{
			System.out.println(s);
		});
		return new SimpleResult(allOrders);
	}
	
	@RequestMapping("/Getin1/{in1}")
	public @ResponseBody SimpleResult Getin1(@PathVariable("in1") int id) {
		List<evaluate> byid = ordersService.byid(id);
		return new SimpleResult(byid);
	}
	@RequestMapping("/Getin2/{in2}")
	public @ResponseBody SimpleResult Getin2(@PathVariable("in2") String un) {
		List<evaluate> mhname = ordersService.Mhname(un);
		return new SimpleResult(mhname);
	}
	@RequestMapping("/Getin3/{in3}")
	public @ResponseBody SimpleResult Getin3(@PathVariable("in3") String zt) {
		List<evaluate> byzt = ordersService.byzt(zt);
		return new SimpleResult(byzt);
	}
	@RequestMapping("/del/{orderId}")
	@ResponseBody
	public SimpleResult del(@PathVariable("orderId") int did){
		int count = ordersService.delByid(did);
		return new SimpleResult(count>0?true:false);
	}
	
	@RequestMapping("/cdgbyID/{orderId}")
	public String GetbyID(@PathVariable("orderId") int order_id,Model model){
		orders or = ordersService.getByid(order_id);
		model.addAttribute("or", or);
		return "order/upd";
	}
	
	@RequestMapping("/updbyid")
	public String upOrder(orders or){
		int os = ordersService.updByid(or);
		if(os!=0){
			return "redirect:list";
		}else{
			return "redirect:list";
		}
	}
	
	@RequestMapping("/list")
	public String to_order() {
		return "order/order_list";
	}
}
